<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * Created by PhpStorm.
 * User: zuoa
 * Date: 2016/11/21 0021
 * Time: 10:08
 */
class Record extends Y_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('record_model');

        $this->record_model->userdata = $this->session->userdata();
    }

    /*
     * 最近的记录
     */
    public function latest($num = 10)
    {
        $this->check_login();
        $records = $this->record_model->get_records($num);
        echo json_encode($records);
    }

    public function today()
    {
        $this->check_login();

        $records = $this->record_model->get_today_records();
        echo json_encode($records);
    }

    public function month()
    {
        $this->check_login();

        $records = $this->record_model->get_month_records();
        echo json_encode($records);
    }

    public function heatmap($num = 10000)
    {
        $this->check_login();

        $records = $this->record_model->get_heatmap_records($num);
        echo json_encode($records);
    }

    public function like($s)
    {
        $this->check_login();

        $records = $this->record_model->search_record($s);
        echo json_encode($records);
    }

    public function detail($aid)
    {
        $this->check_login();

        $records = $this->record_model->get_accident_detail($aid);
        if ($records != null && count($records) > 0) {
            $data["detail"] = $records[0];
            $this->load->view('dashboard/record/detail', $data);
        } else {
            echo "无" . $aid . "相关事故";
        }
        //
    }


}